<?php
/**
 * Created By virus_cms
 * Author: Virus
 * Date: 2020/3/2
 * Time: 13:57
 */

namespace app\common\bussiness;

use think\facade\Db;

class AdminTableBussiness
{
    /**
     * @return array
     */
    public function getAllTables()
    {
        $sql = "SHOW TABLES";
        return Db::query($sql);
    }

    public function getAllTableFields($tableName)
    {
        $sql = "SHOW FULL FIELDS FROM ".$tableName;
        return Db::query($sql);
    }

    public function generatorController($tableName)
    {
        $origin = $tableName;
        $tableName = str_replace('_', '', $tableName);

        // 获取所有字段
        $allField = $this->getAllTableFields($origin);
        $template = $this->templateController($tableName, $allField, $origin);
    }

    public function templateController($tableName, $allField, $origin)
    {
        $str = "";
        foreach ($allField as $key) {
            $str .= "'".$key['Field']."',";
        }
        // 去除末尾逗号
        $str = rtrim($str, ',');
        $lower = $tableName;
        $upper = ucwords($tableName);   // 首字母大写

        // 拼凑一个完整的控制器增删改查为字符串返回  $需要进行转义
        return "
            
        ";
    }
}